package com.buka.config;


import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
public class AppConfig {

    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private String redisPort;

    //创建redission客户端
    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        //指定redis 是集群方式还是单机方式
        String redisAddr = "redis://" + redisHost + ":" + redisPort;
        config.useSingleServer().setAddress(redisAddr);
        //集群方式
//        config.useClusterServers().addNodeAddress(redisAddr,redisAddr,redisAddr)
        return Redisson.create(config);
    }


}
